var username = document.querySelector('#username');
var room = document.querySelector('#room');
var btnConnect = document.querySelector('#connect');
var output = document.querySelector('#output');
var input = document.querySelector('#input');
var btnSend = document.querySelector('#send'); 

var room;
var socket;
btnConnect.onclick = function(){ 
    socket = io("https://49.232.174.112:443");//它默认尝试连接到提供该页面的主机
   
    socket.on('joined',(room,id)=>{
        btnConnect.disabled = true;
        input.disabled = false;
        btnSend.disabled = false;
    })

    socket.on('leaved',(room,id)=>{
        btnConnect.disabled = false;
        input.disabled = true;
        btnSend.disabled = true;
    })

    socket.on('message',(room,data)=>{
        output.value = output.value + data + '\n';
    })
    
    room = room.value;
    socket.emit('join',room);
    
}

btnSend.onclick = function(){
    var data = input.value;
    data = username.value + ': ' + data;
    socket.emit('message',room,data);
    input.value = '';
}